package com.cloud.alibaba.common.util;

import cn.hutool.core.util.ReUtil;
import org.springframework.util.StringUtils;

/**
 * @author taoxinhuan
 * @description: 正则验证类
 * @date 2020/9/8 9:26
 */
public class CheckUtil {
    private static final String EMAIL_PATTEN = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$";
    private static final String ENGLISH_NAME_PATTEN = "^[a-zA-Z]+(-[a-zA-Z]+|[a-zA-Z]+){1}$";

    public static void checkEmail(String email) {
        boolean isMatch = ReUtil.isMatch(EMAIL_PATTEN, email);
        AssertUtils.isTrue(isMatch && StringUtils.hasText(email), "email is not right format");
    }

    /**
     * 验证英文名
     */
    public static void checkEnglishName(String name) {
        boolean isMatch = ReUtil.isMatch(ENGLISH_NAME_PATTEN, name);
        AssertUtils.isTrue(isMatch && StringUtils.hasText(name), "name is not right format");
    }
}
